<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery-1.9.0.js"></script>
    <style>
        .container{
            width:500px;
            height: 50px;
            border:1px solid red;
        }
        .wrap{
            width:50px;
            height: 50px;
            background:green;
            border-radius: 50px ;
        }
    </style>
    <script>
        var left=1;
        var timer;
        var step=1;
        function doStart(){
           
            timer=setInterval(function(){
                if(left==450||left==0){
                    step=step*(-1);
                }
                $(".wrap").css("margin-left",left+"px");
                left=left+step;
            },20);
           
        }
        function doStop(){
            clearInterval(timer);
        }
    </script>
</head>
<body>
    <div class="container">
        <div class="wrap"></div>
    </div>
    <input type="button" value="开始" onclick="doStart()">
    <input type="button" value="停止" onclick="doStop()">
</body>
</html>